package srx.open.com.activity;

import android.content.Intent;
import android.view.View;
import android.widget.TextView;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import srx.open.com.R;
import srx.open.com.bean.CoursePublish;
import srx.open.com.bean.User;
import srx.open.com.utils.OpenToast;
import srx.open.com.utils.UserUtils;
import srx.open.com.widgets.CircleImageView;

/**
 * 课程详细信息内容.
 *
 * @author hailongqiu 356752238@qq.com
 */
public class CourseDetailedInfoActivity extends ExtendBaseActivity {

    private static final String TAG = "CourseDetailedInfoActivity";
    CoursePublish mCoursePublish;

    // 标题栏
    @Bind(R.id.left_tv)
    TextView left_tv;
    @Bind(R.id.right_lay)
    View right_lay;

    // 用户头像.
    @Bind(R.id.avatar_iv)
    CircleImageView avatar_iv;
    // 用户名称.
    @Bind(R.id.username_tv)
    TextView username_tv;
    // 内容
    @Bind(R.id.content_tv)
    TextView content_tv;

    // 联系方式的菜单
    @Bind(R.id.sheet_bg_rlay)
    View sheet_bg_rlay;
    // 手机号码.( 联系）
    @Bind(R.id.phone_num_tv)
    TextView phone_num_tv;

    @Override
    public void initAllViews() {
        setContentView(R.layout.activity_course_detailed_info);
        ButterKnife.bind(this);
        // 初始化传过来的数据.
        initIntentData();
        // 初始化标题栏
        initTitle();
        // 初始化课程内容.
        initCourseDataile();
        // 初始化菜单事件.
        initSheetMenuEvnts();
    }

    private void initSheetMenuEvnts() {
        sheet_bg_rlay.setOnClickListener(mSheetMenuClick);
    }

    View.OnClickListener mSheetMenuClick = new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            sheet_bg_rlay.setVisibility(View.GONE);
        }
    };

    /**
     *  初始化课程的基本信息.
     */
    private void initCourseDataile() {
        if (mCoursePublish != null) {
            String content = mCoursePublish.getContent();
            content_tv.setText("    " + content); // 课程内容.
            User user = mCoursePublish.getUsertt();
            if (user != null) {
                phoneStr = user.getUsername();
                username_tv.setText(user.getNick()); // 用户名.
                phone_num_tv.setText(phoneStr); // 手机号码(账号).
            }
        }
    }

    private void initTitle() {
        right_lay.setVisibility(View.GONE);
        left_tv.setText("课程详情");
        if (mCoursePublish != null) {
            left_tv.setText("" + mCoursePublish.getTitle()); // 课程标题.
        }
    }

    private void initIntentData() {
        Intent intent = getIntent();
        mCoursePublish = (CoursePublish) intent.getSerializableExtra("CoursePublish");
    }

    @OnClick(R.id.left_lay)
    void left_lay(View view) {
        finish();
    }

    /**
     *  联络TA的标题栏关闭按钮.
     */
    @OnClick(R.id.close_btn)
    void close_btn(View view) {
        sheet_bg_rlay.setVisibility(View.GONE); // 隐藏 联络TA 的菜单。
    }

    /**
     *  联络TA
     */
    @OnClick(R.id.relation_btn)
    void relation_btn(View view) {
        sheet_bg_rlay.setVisibility(View.VISIBLE); // 显示 联络TA 的菜单.
    }

    /**
     *  调用手机拨号键盘
     */
    @OnClick(R.id.call_hone_keybarod_lay)
    void call_hone_keybarod_lay(View view) {
        callPhoneNumberKeyboard(phoneStr);
        sheet_bg_rlay.setVisibility(View.GONE);
    }

    /**
     *  发送短信
     */
    @OnClick(R.id.send_sms_lay)
    void send_sms_lay(View view) {
        sendSMS(phoneStr, "我很关注你这个 " + mCoursePublish.getTitle() + " 课程，请速与我联系");
        sheet_bg_rlay.setVisibility(View.GONE);
    }

    /**
     *  发起聊天的界面.(私密TA)
     */
    @OnClick(R.id.private_ta_lay)
    void private_ta_lay(View view) {
        User user = UserUtils.getCurrentUser(mContext);
        if (user != null) {
            // 打开聊天界面.
            Intent intent = new Intent(mContext,
                    ChatActivity.class);
            intent.putExtra("User", mCoursePublish.getUsertt());
            startActivity(intent);
        } else {
            OpenToast.showMsg("需要登录才能私密TA噢");
        }
        sheet_bg_rlay.setVisibility(View.GONE);
    }

    /**
     *  头像点击查看用户信息.
     */
    @OnClick(R.id.avatar_iv)
    void avatar_iv(View view) {

    }

}


